﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Default.Master" Inherits="System.Web.Mvc.ViewPage<AbstractSaaSTemplate.UI.Web.Models.Security.ManageRolesAccessForm>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"><%: Metadata.RootSecurityManageRolesAccessTitle %></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MetaDescription" runat="server"><%: Metadata.RootSecurityManageRolesAccessDescription %></asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MetaKeywords" runat="server"><%: Metadata.RootSecurityManageRolesAccessKeywords %></asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="H1Content" runat="server"><%: Metadata.RootSecurityManageRolesAccessTitle %></asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="InnerBodyClass" runat="server">root security manage-roles-access</asp:Content>

<asp:Content ID="Content6" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm()) { %>
    <table>
        <tr>
            <th class="role"></th>
            <%
            foreach (var feature in this.Model.Features) {
            %><th class="<%: feature.ToString().ToUrlParameterCase() %>"><%: feature.ToFeatureTitle()%></th><% } %>
        </tr>
    
        <%
        var roles = Enum.GetNames(typeof(AccessRoles));
        foreach (var role in roles) {
            var accessRole = AccessRoles.None;
            if (!Enum.TryParse<AccessRoles>(role, out accessRole)) {
                continue;
            }

            if (accessRole == AccessRoles.None) {
                continue;
            }
        %>

        <tr>
            <td>
                <%: accessRole.ToFriendlyMessage()%>
                <%: Html.Hidden("role", accessRole.ToString()) %>
            </td>
        
            <%
            foreach (var feature in this.Model.Features) {
                var association = this.Model.RolesAndFeatures
                    .Where(d =>
                        d.Role == accessRole &&
                        d.Feature == feature)
                    .FirstOrDefault();

                var selected = false;
                if (association != null) {
                    selected = true;
                }
            %><td>
                <input type="checkbox"
                    name="<%: accessRole.ToString() %>-<%: feature.ToString() %>"
                    <% if (selected) { %>
                    checked="checked"<% } %>/>
            </td><% } %>
            <% } %>
        </tr>
    </table>

    <%: Html.AntiForgeryToken() %>
	<input type="submit" value="<%: Expressions.Save %>" />
    <% } %>
</asp:Content>

<asp:Content ID="Content7" ContentPlaceHolderID="StylesReferences" runat="server">
</asp:Content>

<asp:Content ID="Content8" ContentPlaceHolderID="JavascriptReferences" runat="server">
</asp:Content>
